package com.final_project.zombiemenace;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.final_project.zombiemenace.highscore.HighScoreHandler;
import com.final_project.zombiemenace.highscore.IHighscoreHandler;

public class SaveHighScore extends Activity {
	private static final String EMPTY_STRING = "";
	private EditText name;
	private Button saveHighScoreButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_save_high_score);
		name = (EditText)findViewById(R.id.enterName);
		setSaveButtonListener();
	}

	private void setSaveButtonListener() {
		saveHighScoreButton = (Button)findViewById(R.id.saveButton);
		saveHighScoreButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				saveHighScore();
				finish();
			}
		});
	}
	
	private void saveHighScore() {
		IHighscoreHandler hsh = new HighScoreHandler(getApplicationContext());
		String nameString  = name.getText().toString();
		if(nameString.equals(EMPTY_STRING)){
			nameString = getString(R.string.unknown);
		}
		hsh.placeNewHighScore(nameString, getIntent().getIntExtra("score", -1));
		hsh = null;
	}
	
	@Override
	public void onBackPressed() {
		//	 do nothing
	}
}
